const merge = (A, m, B, n) => {
  let i = m - 1,
    j = n - 1,
    length = m + n - 1,
    cur
  // arr = new Array(m + n).fill(0)
  while (i >= 0 || j >= 0) {
    if (i === -1) {
      cur = B[j]
      j -= 1
    } else if (j === -1) {
      cur = A[i]
      i -= 1
    } else if (A[i] > B[j]) {
      cur = A[i]
      i -= 1
    } else {
      cur = B[j]
      j -= 1
    }
    A[length] = cur
    length -= 1
  }
  return A
}

console.log(merge([1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3));